using UnityEngine;

public class SidingAnchor : MonoBehaviour
{
	public Delegate0Args OnMovingUpdate;

	[Range(0f, 1f)]
	[SerializeField]
	private float m_Time = 0.2f;

	private float m_CurTime;

	[SerializeField]
	private RectTransform m_AnchorO;

	[SerializeField]
	private RectTransform m_AnchorT;

	private Vector3 m_TargetPosition;

	private Vector3 m_LastPosition;

	[SerializeField]
	private Vector2 m_MaxOffset = new Vector2(33f, 33f);

	public Vector2 anchorOffset;

	public void SetTargetPosition(Vector3 v)
	{
		m_TargetPosition = v;
		m_LastPosition = m_AnchorO.localPosition;
		m_CurTime = 0f;
		base.enabled = true;
	}

	public void SetTargetPosition(float x, float y)
	{
		Vector2 v = new Vector2(m_MaxOffset.x * x, m_MaxOffset.y * y);
		m_AnchorO.localPosition = v;
	}

	private void Start()
	{
		base.enabled = false;
		m_TargetPosition = Vector3.zero;
	}

	private void Update()
	{
		m_CurTime += Time.deltaTime;
		float t = m_CurTime / m_Time;
		m_AnchorO.localPosition = Vector3.Lerp(m_LastPosition, m_TargetPosition, t);
		m_AnchorT.localPosition = m_AnchorO.localPosition;
		if (m_CurTime > m_Time)
		{
			base.enabled = false;
		}
		if (m_TargetPosition != Vector3.zero)
		{
			Vector3 localPosition = m_AnchorO.localPosition;
			float x = localPosition.x / m_MaxOffset.x;
			Vector3 localPosition2 = m_AnchorO.localPosition;
			anchorOffset = new Vector3(x, localPosition2.y / m_MaxOffset.y);
			anchorOffset.x = Mathf.Round(anchorOffset.x * 10f) * 0.1f;
			anchorOffset.y = Mathf.Round(anchorOffset.y * 10f) * 0.1f;
			Pools.Cue.Siding(anchorOffset);
		}
	}
}
